﻿namespace eeenno.SpeeedReaderUI.NativeWebBrowser.Win32
{
    using eeenno.SpeeedReaderUI.NativeWebBrowser.Threading;
    using System;
    using System.Runtime.InteropServices;
    using System.Text;

    public sealed class Core
    {
        [Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus and related functionality.", false)]
        internal const uint BatteryLifeUnknown = uint.MaxValue;
        [Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus and related functionality.", false)]
        public const byte BatteryPercentageUnknown = 0xff;
        internal const uint CLR_INVALID = uint.MaxValue;
        private const int ERROR_INSUFFICIENT_BUFFER = 0x7a;
        private const int ERROR_NOT_SUPPORTED = 50;
        internal const int FILE_ANY_ACCESS = 0;
        internal const int FILE_DEVICE_HAL = 0x101;
        internal const int INFINITE = -1;
        public const int INVALID_HANDLE_VALUE = -1;
        internal static int IOCTL_HAL_GET_DEVICEID = 0x1010054;
        internal const int METHOD_BUFFERED = 0;
        public const int MWMO_INPUTAVAILABLE = 4;

        public static void CheckHandle(IntPtr hPtr)
        {
            if ((hPtr == IntPtr.Zero) || (((int) hPtr) == -1))
            {
                throw new WinAPIException("Invalid Handle Value", 0);
            }
        }

        [DllImport("coredll.dll", SetLastError=true)]
        public static extern bool CloseHandle(IntPtr hObject);
        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.EventWaitHandle to work with event handles", false)]
        public static IntPtr CreateEvent(bool bManualReset, bool bInitialState, string lpName)
        {
            return NativeMethods.CreateEvent(IntPtr.Zero, bManualReset, bInitialState, lpName);
        }

        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.MutexEx to create a named Mutex", false)]
        public static IntPtr CreateMutex(IntPtr lpMutexAttributes, bool bInitialOwner, string lpName)
        {
            IntPtr ptr = NativeMethods.CreateMutex(lpMutexAttributes, bInitialOwner, lpName);
            if (ptr == IntPtr.Zero)
            {
                throw new WinAPIException("CreateMutex failed.", (int) ptr);
            }
            if (Marshal.GetLastWin32Error() == 0xb7)
            {
                throw new WinAPIException("Mutex already exists", (int) ptr);
            }
            return ptr;
        }

        [DllImport("coredll", SetLastError=true)]
        public static extern IntPtr CreateSolidBrush(int crColor);
        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Win32Window.FindWindow found in the eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms assembly.", false)]
        public static IntPtr FindWindow(string lpClassName, string lpWindowName)
        {
            IntPtr zero = IntPtr.Zero;
            zero = FindWindowCE(lpClassName, lpWindowName);
            if (zero == IntPtr.Zero)
            {
                throw new WinAPIException("Failed to find Window");
            }
            return zero;
        }

        [DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)]
        private static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);
        [DllImport("coredll", EntryPoint="FormatMessageW")]
        internal static extern int FormatMessage(FormatMessageFlags dwFlags, int lpSource, int dwMessageId, int dwLanguageId, out IntPtr lpBuffer, int nSize, int[] Arguments);
        public static IntPtr GetDC(IntPtr hWnd)
        {
            IntPtr zero = IntPtr.Zero;
            zero = GetDCCE(hWnd);
            if (zero == IntPtr.Zero)
            {
                throw new WinAPIException("Failed to get DC.");
            }
            return zero;
        }

        [DllImport("coredll", EntryPoint="GetDC", SetLastError=true)]
        private static extern IntPtr GetDCCE(IntPtr hWnd);
        public static Guid GetDeviceGuid()
        {
            byte[] rawDeviceID = GetRawDeviceID();
            int num = BitConverter.ToInt32(rawDeviceID, 4);
            int num2 = BitConverter.ToInt32(rawDeviceID, 8);
            int num3 = BitConverter.ToInt32(rawDeviceID, 12);
            int num4 = BitConverter.ToInt32(rawDeviceID, 0x10);
            byte[] dst = new byte[0x10];
            Buffer.BlockCopy(rawDeviceID, (num + num2) - 10, dst, 0, 10);
            Buffer.BlockCopy(rawDeviceID, (num3 + num4) - 6, dst, 10, 6);
            return new Guid(dst);
        }

        public static string GetDeviceID()
        {
            byte[] rawDeviceID = GetRawDeviceID();
            int num = BitConverter.ToInt32(rawDeviceID, 4);
            int num2 = BitConverter.ToInt32(rawDeviceID, 8);
            int num3 = BitConverter.ToInt32(rawDeviceID, 12);
            int num4 = BitConverter.ToInt32(rawDeviceID, 0x10);
            StringBuilder builder = new StringBuilder();
            for (int i = num; i < (num + num2); i++)
            {
                builder.Append(string.Format("{0:X2}", rawDeviceID[i]));
            }
            builder.Append("-");
            for (int j = num3; j < (num3 + num4); j++)
            {
                builder.Append(string.Format("{0:X2}", rawDeviceID[j]));
            }
            return builder.ToString();
        }

        [DllImport("coredll.dll", EntryPoint="GetModuleHandleW", SetLastError=true)]
        public static extern IntPtr GetModuleHandle(string moduleName);
        [DllImport("coredll", SetLastError=true)]
        public static extern int GetObject(IntPtr hObj, int cb, byte[] objdata);
        [DllImport("coredll.dll", EntryPoint="GetProcAddressW", SetLastError=true)]
        public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
        private static byte[] GetRawDeviceID()
        {
            int bytesReturned = 0;
            int num2 = 0x100;
            byte[] array = new byte[num2];
            bool flag = false;
            BitConverter.GetBytes(num2).CopyTo(array, 0);
            while (!flag)
            {
                if (!KernelIoControl(IOCTL_HAL_GET_DEVICEID, null, 0, array, num2, ref bytesReturned))
                {
                    int num3 = Marshal.GetLastWin32Error();
                    switch (num3)
                    {
                        case 50:
                            //throw new NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this device", new Exception(num3));

                        case 0x7a:
                        {
                            num2 = BitConverter.ToInt32(array, 0);
                            array = new byte[num2];
                            BitConverter.GetBytes(num2).CopyTo(array, 0);
                            continue;
                        }
                    }
                    throw new Exception("Unexpected error: " + num3);
                }
                flag = true;
            }
            return array;
        }

        public static SystemInfo GetSystemInfo()
        {
            SystemInfo pSI = new SystemInfo();
            try
            {
                GetSystemInfoCE(out pSI);
            }
            catch (Exception)
            {
                throw new WinAPIException("Error retrieving system info.");
            }
            return pSI;
        }

        [DllImport("coredll", EntryPoint="GetSystemInfo", SetLastError=true)]
        internal static extern void GetSystemInfoCE(out SystemInfo pSI);
        [Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus property.", true)]
        public static SystemPowerStatus GetSystemPowerStatusEx(bool update)
        {
            SystemPowerStatus pStatus = new SystemPowerStatus();
            try
            {
                GetSystemPowerStatusExCE(out pStatus, update);
            }
            catch (Exception)
            {
                throw new WinAPIException("Error retrieving system power status.");
            }
            return pStatus;
        }

        [DllImport("coredll.dll", EntryPoint="GetSystemPowerStatusEx", SetLastError=true)]
        private static extern bool GetSystemPowerStatusExCE(out SystemPowerStatus pStatus, bool fUpdate);
        public static int GetTextColor(IntPtr hdc)
        {
            CheckHandle(hdc);
            return GetTextColorCE(hdc);
        }

        [DllImport("coredll.dll", EntryPoint="GetTextColor", SetLastError=true)]
        private static extern int GetTextColorCE(IntPtr hdc);
        public static IntPtr GetWindowDC(IntPtr hWnd)
        {
            IntPtr zero = IntPtr.Zero;
            zero = GetWindowDCCE(hWnd);
            if (zero == IntPtr.Zero)
            {
                throw new WinAPIException("Failed to get DC.");
            }
            return zero;
        }

        [DllImport("coredll.dll", EntryPoint="GetWindowDC", SetLastError=true)]
        private static extern IntPtr GetWindowDCCE(IntPtr hWnd);
        public static MemoryStatus GlobalMemoryStatus()
        {
            MemoryStatus msce = new MemoryStatus();
            GlobalMemoryStatusCE(out msce);
            return msce;
        }

        [DllImport("coredll", EntryPoint="GlobalMemoryStatus")]
        internal static extern void GlobalMemoryStatusCE(out MemoryStatus msce);
        [DllImport("coredll.dll", SetLastError=true)]
        public static extern bool IsBadCodePtr(IntPtr fn);
        [DllImport("coredll.dll", SetLastError=true)]
        internal static extern bool KernelIoControl(int dwIoControlCode, byte[] inBuf, int inBufSize, byte[] outBuf, int outBufSize, ref int bytesReturned);
        [DllImport("coredll.dll", SetLastError=true)]
        internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
        public static IntPtr LoadLibrary(string library)
        {
            IntPtr ptr = LoadLibraryCE(library);
            if ((ptr.ToInt32() <= 0x1f) & (ptr.ToInt32() >= 0))
            {
                throw new WinAPIException("Failed to load library " + library, Marshal.GetLastWin32Error());
            }
            return ptr;
        }

        [DllImport("coredll.dll", EntryPoint="LoadLibraryW", SetLastError=true)]
        internal static extern IntPtr LoadLibraryCE(string lpszLib);
        [CLSCompliant(false)]
        public static Wait MsgWaitForMultipleObjects(IntPtr[] Handles, int Timeout, WakeMask Mask)
        {
            return (Wait) NativeMethods.MsgWaitForMultipleObjectsEx((uint) Handles.Length, Handles, (uint) Timeout, (uint) Mask, 0);
        }

        [DllImport("coredll.dll", SetLastError=true)]
        internal static extern bool PostKeybdMessage(IntPtr hwnd, uint vKey, KeyStateFlags flags, uint cCharacters, KeyStateFlags[] pShiftStateBuffer, uint[] pCharacterBuffer);
        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.EventWaitHandle to work with event handles", false)]
        public static bool PulseEvent(IntPtr hEvent)
        {
            return NativeMethods.EventModify(hEvent, NativeMethods.EVENT.PULSE);
        }

        public static long QueryPerformanceCounter()
        {
            long lpPerformanceCount = 0L;
            if (QueryPerformanceCounterCE(ref lpPerformanceCount) == 0)
            {
                throw new WinAPIException("The hardware does not support a high frequency counter.");
            }
            return lpPerformanceCount;
        }

        [DllImport("coredll.dll", EntryPoint="QueryPerformanceCounter", SetLastError=true)]
        internal static extern int QueryPerformanceCounterCE(ref long lpPerformanceCount);
        public static long QueryPerformanceFrequency()
        {
            long lpFrequency = 0L;
            if (QueryPerformanceFrequencyCE(ref lpFrequency) == 0)
            {
                throw new WinAPIException("The hardware does not support a high frequency counter.");
            }
            return lpFrequency;
        }

        [DllImport("coredll.dll", EntryPoint="QueryPerformanceFrequency", SetLastError=true)]
        internal static extern int QueryPerformanceFrequencyCE(ref long lpFrequency);
        public static void Rectangle(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
        {
            CheckHandle(hdc);
            if (!Convert.ToBoolean(RectangleCE(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect)))
            {
                throw new WinAPIException("Failed to draw rectangle.");
            }
        }

        [DllImport("coredll", EntryPoint="Rectangle", SetLastError=true)]
        private static extern uint RectangleCE(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
        public static void ReleaseDC(IntPtr hWnd, IntPtr hDC)
        {
            CheckHandle(hDC);
            if (ReleaseDCCE(hWnd, hDC) == 0)
            {
                throw new WinAPIException("Failed to release DC.");
            }
        }

        [DllImport("coredll.dll", EntryPoint="ReleaseDC", SetLastError=true)]
        private static extern int ReleaseDCCE(IntPtr hWnd, IntPtr hDC);
        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.MutexEx to create a named Mutex", false)]
        public static bool ReleaseMutex(IntPtr hMutex)
        {
            bool flag = NativeMethods.ReleaseMutex(hMutex);
            if (!flag)
            {
                throw new WinAPIException("Error releasing Mutex.", Marshal.GetLastWin32Error());
            }
            return flag;
        }

        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.EventWaitHandle to work with event handles", false)]
        public static bool ResetEvent(IntPtr hEvent)
        {
            return NativeMethods.EventModify(hEvent, NativeMethods.EVENT.RESET);
        }

        public static IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj)
        {
            IntPtr zero = IntPtr.Zero;
            CheckHandle(hdc);
            CheckHandle(hgdiobj);
            zero = SelectObjectCE(hdc, hgdiobj);
            if (zero == IntPtr.Zero)
            {
                throw new WinAPIException("Failed. Selected object is not a region.");
            }
            return zero;
        }

        [DllImport("coredll.dll", EntryPoint="SelectObject", SetLastError=true)]
        private static extern IntPtr SelectObjectCE(IntPtr hdc, IntPtr hgdiobj);
        public static void SendKeyboardKey(byte VirtualKey)
        {
            SendKeyboardKey(VirtualKey, true);
        }

        public static void SendKeyboardKey(byte VirtualKey, bool Silent)
        {
            SendKeyboardKey(VirtualKey, Silent, KeyActionState.Press);
        }

        public static void SendKeyboardKey(byte VirtualKey, bool Silent, KeyActionState State)
        {
            int dwExtraInfo = Silent ? 4 : 0;
            if ((State & KeyActionState.Down) > ((KeyActionState) 0))
            {
                keybd_event(VirtualKey, 0, 0, dwExtraInfo);
            }
            if ((State & KeyActionState.Up) > ((KeyActionState) 0))
            {
                keybd_event(VirtualKey, 0, 2, dwExtraInfo);
            }
        }

        public static void SendKeyboardString(string Keys)
        {
            SendKeyboardString(Keys, KeyStateFlags.Down, IntPtr.Zero);
        }

        public static void SendKeyboardString(string Keys, KeyStateFlags Flags)
        {
            SendKeyboardString(Keys, Flags, IntPtr.Zero);
        }

        public static void SendKeyboardString(string Keys, KeyStateFlags Flags, IntPtr hWnd)
        {
            uint[] pCharacterBuffer = new uint[Keys.Length];
            KeyStateFlags[] pShiftStateBuffer = new KeyStateFlags[Keys.Length];
            KeyStateFlags[] flagsArray2 = new KeyStateFlags[] { KeyStateFlags.Dead };
            for (int i = 0; i < Keys.Length; i++)
            {
                pShiftStateBuffer[i] = Flags;
                pCharacterBuffer[i] = Convert.ToUInt32(Keys[i]);
            }
            PostKeybdMessage(hWnd, 0, Flags, (uint) pCharacterBuffer.Length, pShiftStateBuffer, pCharacterBuffer);
            PostKeybdMessage(hWnd, 0, flagsArray2[0], 1, flagsArray2, pCharacterBuffer);
        }

        public static int SetBkColor(IntPtr hdc, int crColor)
        {
            CheckHandle(hdc);
            uint num = SetBkColorCE(hdc, crColor);
            if (num == uint.MaxValue)
            {
                throw new WinAPIException("Failed to set color");
            }
            return Convert.ToInt32(num);
        }

        [DllImport("coredll.dll", EntryPoint="SetBkColor", SetLastError=true)]
        private static extern uint SetBkColorCE(IntPtr hdc, int crColor);
        public static BackMode SetBkMode(IntPtr hdc, BackMode iBkMode)
        {
            CheckHandle(hdc);
            int num = SetBkModeCE(hdc, (int) iBkMode);
            if (num == 0)
            {
                throw new WinAPIException("Failed to set BkMode");
            }
            return (BackMode) num;
        }

        [DllImport("coredll.dll", EntryPoint="SetBkMode", SetLastError=true)]
        private static extern int SetBkModeCE(IntPtr hdc, int iBkMode);
        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.EventWaitHandle to work with event handles", false)]
        public static bool SetEvent(IntPtr hEvent)
        {
            return NativeMethods.EventModify(hEvent, NativeMethods.EVENT.SET);
        }

        public static int SetTextColor(IntPtr hdc, int crColor)
        {
            CheckHandle(hdc);
            uint num = SetTextColorCE(hdc, crColor);
            if (num == uint.MaxValue)
            {
                throw new WinAPIException("Failed to set color");
            }
            return Convert.ToInt32(num);
        }

        [DllImport("coredll.dll", EntryPoint="SetTextColor", SetLastError=true)]
        private static extern uint SetTextColorCE(IntPtr hdc, int crColor);
        [DllImport("coredll.dll", SetLastError=true)]
        internal static extern bool SystemParametersInfo(SystemParametersInfoAction action, int size, byte[] buffer, SystemParametersInfoFlags winini);
        [CLSCompliant(false)]
        public static Wait WaitForMultipleObjects(IntPtr[] Handles, bool WaitForAll, int Timeout)
        {
            return (Wait) NativeMethods.WaitForMultipleObjects((uint) Handles.Length, Handles, WaitForAll, (uint) Timeout);
        }

        [Obsolete("Use eeenno.SpeeedReaderUI.NativeWebBrowser.Threading.EventWaitHandle to work with event handles", false), CLSCompliant(false)]
        public static Wait WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds)
        {
            return (Wait) NativeMethods.WaitForSingleObject(hHandle, Convert.ToInt32(dwMilliseconds));
        }

        [Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus and related functionality.", false)]
        public enum ACLineStatus : byte
        {
            BackupPower = 2,
            Offline = 0,
            Online = 1,
            Unknown = 0xff
        }

        public enum BackMode
        {
            OPAQUE = 2,
            TRANSPARENT = 1
        }

        [Flags, Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus and related functionality.", false)]
        public enum BatteryFlag : byte
        {
            Charging = 8,
            Critical = 4,
            High = 1,
            Low = 2,
            NoBattery = 0x80,
            Unknown = 0xff
        }

        [Flags]
        public enum FormatMessageFlags
        {
            AllocateBuffer = 0x100,
            ArgumentArray = 0x2000,
            FromHModule = 0x800,
            FromString = 0x400,
            FromSystem = 0x1000,
            IgnoreInserts = 0x200,
            MaxWidthMask = 0xff
        }

        public enum GDIRegion
        {
            COMPLEXREGION = 3,
            NULLREGION = 1,
            SIMPLEREGION = 2
        }

        public enum KeyActionState
        {
            Down = 1,
            Press = 3,
            Up = 2
        }

        private enum KeyEvents
        {
            ExtendedKey = 1,
            KeyUp = 2,
            Silent = 4
        }

        [Flags]
        public enum KeyStateFlags
        {
            AnyAlt = 0x10000000,
            AnyCtrl = 0x40000000,
            AnyShift = 0x20000000,
            AsyncDown = 2,
            Capital = 0x8000000,
            Dead = 0x20000,
            Down = 0x80,
            Language1 = 0x8000,
            LeftAlt = 0x1000000,
            LeftCtrl = 0x4000000,
            LeftShift = 0x2000000,
            LeftWin = 0x800000,
            NoCharacter = 0x10000,
            NumLock = 0x1000,
            PrevDown = 0x40,
            RightAlt = 0x100000,
            RightCtrl = 0x400000,
            RightShift = 0x200000,
            RightWin = 0x80000,
            Toggled = 1
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct MemoryStatus
        {
            internal uint dwLength;
            public int MemoryLoad;
            public int TotalPhysical;
            public int AvailablePhysical;
            public int TotalPageFile;
            public int AvailablePageFile;
            public int TotalVirtual;
            public int AvailableVirtual;
        }

        public enum ProcessorArchitecture : short
        {
            Alpha = 2,
            Alpha64 = 7,
            ARM = 5,
            IA64 = 6,
            Intel = 0,
            MIPS = 1,
            PPC = 3,
            SHX = 4,
            Unknown = -1
        }

        public enum ProcessorType
        {
            Alpha_21064 = 0x5248,
            ARM_7TDMI = 0x11171,
            ARM720 = 0x720,
            ARM820 = 0x820,
            ARM920 = 0x920,
            Hitachi_SH3 = 0x2713,
            Hitachi_SH3E = 0x2714,
            Hitachi_SH4 = 0x2715,
            Intel_386 = 0x182,
            Intel_486 = 0x1e6,
            Intel_IA64 = 0x898,
            Intel_Pentium = 0x24a,
            Intel_PentiumII = 0x2ae,
            MIPS_R4000 = 0xfa0,
            Motorola_821 = 0x335,
            PPC_403 = 0x193,
            PPC_601 = 0x259,
            PPC_603 = 0x25b,
            PPC_604 = 0x25c,
            PPC_620 = 620,
            SHx_SH3 = 0x67,
            SHx_SH4 = 0x68,
            StrongARM = 0xa11
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SystemInfo
        {
            public eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Core.ProcessorArchitecture ProcessorArchitecture;
            internal ushort wReserved;
            public int PageSize;
            public int MinimumApplicationAddress;
            public int MaximumApplicationAddress;
            public int ActiveProcessorMask;
            public int NumberOfProcessors;
            public eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Core.ProcessorType ProcessorType;
            public int AllocationGranularity;
            public short ProcessorLevel;
            public short ProcessorRevision;
        }

        public enum SystemParametersInfoAction
        {
            GetBatteryIdleTimeout = 0xfc,
            GetExternalIdleTimeout = 0xfe,
            GetFontSmoothingContrast = 0x200c,
            GetMouse = 3,
            GetOemInfo = 0x102,
            GetPlatformType = 0x101,
            GetScreenSaveTimeout = 14,
            GetShowSounds = 0x38,
            GetWakeupIdleTimeout = 0x100,
            GetWheelScrollLines = 0x68,
            GetWorkArea = 0x30,
            SetBatteryIdleTimeout = 0xfb,
            SetDeskPattern = 0x15,
            SetDeskWallpaper = 20,
            SetExternalIdleTimeout = 0xfd,
            SetFontSmoothingContrast = 0x200d,
            SetMouse = 4,
            SetScreenSaveTimeout = 15,
            SetShowSounds = 0x39,
            SetWakeupIdleTimeout = 0xff,
            SetWheelScrollLines = 0x69,
            SetWorkArea = 0x2f
        }

        public enum SystemParametersInfoFlags
        {
            None,
            UpdateIniFile,
            SendChange
        }

        [StructLayout(LayoutKind.Sequential), Obsolete("Use the .NET compliant eeenno.SpeeedReaderUI.NativeWebBrowser.Windows.Forms.SystemInformationEx.PowerStatus and related functionality.", false)]
        public struct SystemPowerStatus
        {
            public eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Core.ACLineStatus ACLineStatus;
            public eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Core.BatteryFlag BatteryFlag;
            public byte BatteryLifePercent;
            internal byte Reserved1;
            public int BatteryLifeTime;
            private uint dwBatteryFullLifeTime;
            internal byte Reserved2;
            public eeenno.SpeeedReaderUI.NativeWebBrowser.Win32.Core.BatteryFlag BackupBatteryFlag;
            public byte BackupBatteryLifePercent;
            internal byte Reserved3;
            private uint dwBackupBatteryLifeTime;
            private uint dwBackupBatteryFullLifeTime;
            public int BatteryFullLifeTime
            {
                get
                {
                    if (this.dwBatteryFullLifeTime == uint.MaxValue)
                    {
                        return 0;
                    }
                    return Convert.ToInt32(this.dwBatteryFullLifeTime);
                }
            }
            public int BackupBatteryLifeTime
            {
                get
                {
                    if (this.dwBackupBatteryLifeTime == uint.MaxValue)
                    {
                        return 0;
                    }
                    return Convert.ToInt32(this.dwBackupBatteryLifeTime);
                }
            }
            public int BackupBatteryFullLifeTime
            {
                get
                {
                    if (this.dwBackupBatteryFullLifeTime == uint.MaxValue)
                    {
                        return 0;
                    }
                    return Convert.ToInt32(this.dwBackupBatteryFullLifeTime);
                }
            }
        }

        public enum Wait
        {
            Abandoned = 0x80,
            Failed = -1,
            Object = 0
        }

        [Flags]
        public enum WakeMask
        {
            AllEvents = 0x3f,
            AllInput = 0x7f,
            Input = 7,
            Key = 1,
            Mouse = 6,
            MouseButton = 4,
            MouseMove = 2,
            Paint = 0x20,
            PostMessage = 8,
            SendMessage = 0x40,
            Timer = 0x10
        }
    }
}

